﻿using System;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.Exceptions;
using Autodesk.Revit.UI;
using YArchitech.Controls;
using YArchitech.Revit;

namespace HYFloorPipeModule
{
	[Transaction(TransactionMode.Manual)]
	[Regeneration(RegenerationOption.Manual)]
	public class DefineFloorPipe : HYNoTranExternalCommand
	{
		public override Result HYExecute()
		{
			Transaction transaction = new Transaction(base.Doc, "自定义盘管");
			transaction.Start();
			Result result;
			try
			{
				DefiningFloorPipe definingFloorPipe = new DefiningFloorPipe(base.UiDoc);
				if (!definingFloorPipe.MakeGroup())
				{
					YJKMessageBox.Information("盘管成组失败！\n" + definingFloorPipe.ErrorMsg);
				}
				else
				{
					YJKMessageBox.Information("盘管成组成功！");
				}
				transaction.Commit();
				result = Autodesk.Revit.UI.Result.Succeeded;
			}
			catch (Autodesk.Revit.Exceptions.OperationCanceledException)
			{
				transaction.Commit();
				result = Autodesk.Revit.UI.Result.Succeeded;
			}
			catch (Exception ex)
			{
				YJKMessageBox.Information(ex.Message + ex.StackTrace);
				if ((int)transaction.GetStatus() != 3)
				{
					transaction.RollBack();
				}
				result = Autodesk.Revit.UI.Result.Failed;
			}
			return result;
		}
	}
}
